<?php

/**
 * as51 酒店预订搜索
 * ============================================================================
 * 版权所有 2005-2010 上海商派网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.ecshop.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: zhaohong $
 * $Id: search_hotel.php 17067 2010-03-26 03:59:37Z liuhui $
*/

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
$smarty->assign('guid','search_hotel');


$act=$_REQUEST['act'];
$smarty->assign('act',$act);

/* 页面的缓存ID */
$hotel_id=$_REQUEST['hotel_id'];
$cache_id = sprintf('%X', crc32($hotel_id . '-'. $display . '-' . $sort  .'-' . $order  .'-' . $page . '-' . $size . '-' . $_SESSION['user_rank'] . '-' .$_CFG['lang'] .'-'. $filter_attr_str));

if (!$smarty->is_cached('booking_hotel.dwt', $cache_id))
{
	
	if(empty($act)||$act=='order'){
		if(empty($hotel_id)){
			hy_header('search_hotel.php');
		}
		//城市区列表
		$hotel_city_list=get_hotel_city_list();
		$smarty->assign('hotel_city_list',$hotel_city_list);
		//酒店信息
		$hotel_inf=get_goods($hotel_id);
		$smarty->assign('hotel_inf',$hotel_inf);
		//print_pre_r($hotel_inf);
		//本市行政区列表
		$here_area_list=get_area($hotel_inf['city_id']);
		$smarty->assign('here_area_list',$here_area_list);
		//本市商业区列表
		$biz_srh=array();
		$biz_srh['city_id']=$hotel_inf['city_id'];
		$biz_zone_list=get_biz_zone_list($biz_srh);
		$smarty->assign('biz_zone_list',$biz_zone_list);
		//周边城市
		$here_city_list=array();
		if(!empty($hotel_city_list)){
			foreach ($hotel_city_list as $key=>$val){
				if($val['father_id']==$hotel_inf['father_id']){
					$here_city_list[]=$val;
				}
			}
		}
		$smarty->assign('here_city_list',$here_city_list);
		//本市推荐酒店
		$push_param=array();
		$push_param['city_id']=$hotel_inf['city_id'];
		$push_param['is_hot']=1;
		$hotel_push_list=get_hotel_list($push_param,20,1);//执行搜索
		$smarty->assign('hotel_push_list',$hotel_push_list['list']);

		// 页面标题
		$smarty->assign('page_title', '预订'.$hotel_inf['goods_name']);
		// 当前位置
		$ur_here=array();
		$ur_here[]=array('txt'=>'酒店搜索预订','url'=>'?');
		if($hotel_inf['city_name']){$ur_here[]=array('txt'=>$hotel_inf['city_name'],'url'=>'?city_id='.$hotel_inf['city_id']);}
		if($hotel_inf['area']){$ur_here[]=array('txt'=>$hotel_inf['area'],'url'=>'?area_id='.$hotel_inf['area_id']);}
		if($hotel_inf['biz_name']){$ur_here[]=array('txt'=>$hotel_inf['biz_name'],'url'=>'?area_id='.$hotel_inf['biz_area_id']);}
		if($hotel_inf['goods_name']){$ur_here[]=array('txt'=>$hotel_inf['goods_name'],'url'=>'');}
		$ur_here[]=array('txt'=>'五星酒店','url'=>'?hotel_star=5');
		$ur_here[]=array('txt'=>'四星酒店','url'=>'?hotel_star=4');
		$ur_here[]=array('txt'=>'三星酒店','url'=>'?hotel_star=3');
		$ur_here[]=array('txt'=>'二星酒店','url'=>'?hotel_star=2');
		$ur_here[]=array('txt'=>'一星酒店','url'=>'?hotel_star=1');
		$ur_here[]=$smarty->assign('ur_here',get_url_here($ur_here));  // 当前位置
		//酒店区域
		$ur_here=array();
		if($hotel_inf['city_name']){$ur_here[]=array('txt'=>$hotel_inf['city_name'],'url'=>'?city_id='.$hotel_inf['city_id']);}
		if($hotel_inf['area']){$ur_here[]=array('txt'=>$hotel_inf['area'],'url'=>'?area_id='.$hotel_inf['area_id']);}
		if($hotel_inf['biz_name']){$ur_here[]=array('txt'=>$hotel_inf['biz_name'],'url'=>'?area_id='.$hotel_inf['biz_area_id']);}
		$ur_here[]=$smarty->assign('hotel_here',get_url_here($ur_here));  // 当前位置
		
		if(empty($act)){
			//房型列表
			$room_srh=array();
			$room_srh['hotel_id']=$hotel_inf['goods_id'];
			if(!empty($room_srh)){
				$room_kind_list=get_room_kind_list($room_srh);
			}
			$smarty->assign('room_kind_list',$room_kind_list);
			//图片
			$hotel_img_list=get_goods_img_list($hotel_inf['goods_id'],1,4);
			$smarty->assign('hotel_img_list',$hotel_img_list);
			//评论
			/* 初始化分页信息 */
			$page = isset($_REQUEST['page'])   && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;
			$size = isset($_CFG['page_size'])  && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 10;
			$filter_attr_str = isset($_REQUEST['filter_attr']) ? trim($_REQUEST['filter_attr']) : '0';
			$filter_attr_str = urldecode($filter_attr_str);
			$filter_attr = empty($filter_attr_str) ? '' : explode('.', trim($filter_attr_str));

			$pager['search']=array();//分页链接参数
			$pager['search']['hotel_id']=$hotel_id;

			$comm_srch=array();
			$comm_srch['comment_type']=0;
			$comm_srch['id_value']=$hotel_inf['goods_id'];
			$comm_srch['status']=1;
			$comment_list=get_comment_list_as($comm_srch,$size,$page);
			$count=$comment_list['count'];
			//返回搜索form的值
			$pager = get_pager('booking_hotel.php', $pager['search'], $count, $page, $size);
			$smarty->assign('comment_list', $comment_list);
			$smarty->assign('pager', $pager);
		}elseif ($act=='order'){
			//房型信息
			$room_id=$_REQUEST['room_id'];
			if(empty($room_id)){
				hy_header('booking_hotel.php?hotel_id='.$hotel_id);
			}
			$room_inf=get_room_kind($room_id);
			//print_pre_r($room_inf);
			$smarty->assign('room_inf', $room_inf);
		}
		
//print_pre_r($comment_list);
	}elseif($act=='add_order'){//下订单
		//注册账户
		if(empty($user_id)){//未登录或未注册
			$mobile=trim($_POST['mobile']);
			$users_inf=get_users('',$mobile);
			if(!empty($users_inf)){
				$user_id=$users_inf['user_id'];
				//登陆
				$_SESSION['user_id']=$users_inf['user_id'];
				$_SESSION['user_name']=$users_inf['user_name'];
				$smarty->assign('user_id',$users_inf['user_id']);
				$smarty->assign('user_name',$users_inf['user_name']);
			}else{
				$user_data=array();//注册信息
				$user_data['username']=$mobile;//以此作为注册账户
				$user_data['password']=$mobile;//以此作为密码
				$user_data['email']=$_POST['email'];//
				$user_data['office_phone']=$_POST['tel'];//
				$user_data['home_phone']=$_POST['tel'];//
				$user_data['tel']=array($_POST['tel']);//
				$user_data['mobile_phone']=$mobile;//
				$user_data['address']=array($_POST['address']);//
				$user_data['consignee']=array($_POST['consignee']);//
//print_pre_r($user_data);;exit;
				add_users($user_data);
				$user_id=$_SESSION['user_id'];
			}
		}
		//下单
		$hotel_id=$_POST['hotel_id'];
		$room_id=$_POST['room_id'];
		if(empty($hotel_id)||empty($room_id)){
			hy_header('search_hotel.php');
		}
        $hotel_inf=get_goods($hotel_id);
        $room_inf=get_room_kind($room_id);
        if(empty($hotel_inf)||empty($room_inf)){
        	hy_header('search_hotel.php');
        }
        $order_data=array();
        $order_goods_data=array();
        //订单信息
        require(ROOT_PATH . 'includes/lib_order.php');
        $order_data['order_sn']=get_order_sn(); //获取新订单号;
        $order_data['user_id']=$user_id;
        $order_data['consignee']=$_POST['consignee'];
        $order_data['address']=$_POST['address'];
        $order_data['mobile']=$_POST['mobile'];
        $order_data['email']=$_POST['email'];
        $order_data['fax']=$_POST['fax'];
        $order_data['add_time']=$now_time;
        $order_data['order_amount']=$_POST['order_total'];
        $order_data['goods_amount']=$_POST['order_total'];
        $order_data['discount']='';
        $order_data['order_type']='1';//订单类型：1酒店预订，2机票预订3旅游预订
        $order_data['intake_person']=serialize($_POST['intake_person']);
        $order_data['ensure_type']=$_POST['ensure_type'];
        $order_data['late_time']=$_POST['late_time'];
        $order_data['other_infor']=htmlspecialchars(stripslashes($_POST['other_infor']));
        //添加订单
        $order_id=add_order_info($order_data);
        
        //预订的酒店信息
        $order_goods_data['order_id']=$order_id;
        $order_goods_data['goods_id']=$hotel_id;
        $order_goods_data['goods_name']=$hotel_inf['goods_name'];
        $order_goods_data['goods_sn']=$hotel_inf['goods_sn'];
        $order_goods_data['goods_number']=$_POST['room_num'];
        $order_goods_data['goods_price']=$room_inf['average_price'];
        $order_goods_data['room_kind_id']=$room_inf['rt_id'];
        $order_goods_data['room_kind_name']=$room_inf['rt_name'];
        $order_goods_data['come_time']=strtotime($_POST['from_time_ord'].' 00:00:00');
        $order_goods_data['away_time']=strtotime($_POST['to_time_ord'].' 23:59:59');
        //添加订单的酒店
        add_order_goods($order_goods_data);
        
        show_message("酒店预订成功！谢谢您的惠顾！",'返回首页','index.php');
        //print_pre_r($order_data);
        //print_pre_r($order_goods_data);exit;
	}elseif ($act=='do_comment'){//点评
		$data=$_POST;
	    $comment_data=array();
	    $comment_data['server_rank']=$data['server_rank'];
	    $comment_data['price_rank']=$data['price_rank'];
	    $comment_data['clean_rank']=$data['clean_rank'];
	    $comment_data['establishment_rank']=$data['establishment_rank'];
	    $comment_data['id_value']=$data['hotel_id'];
	    $comment_data['comment_type']=0;
	    $comment_data['content']=$data['content'];
	    $comment_data['status']=1;
	    $comment_data['user_name']=$user_name;
	    $comment_data['user_id']=$user_id;
	    $comment_data['add_time']=time();
	    $comment_data['ip_address']=real_ip();
	    add_comment($comment_data);
	    hy_header('?hotel_id='.$hotel_id);
	}

	
	
	$smarty->display('booking_hotel.dwt',$cache_id);
}


?>